package xyz.icxl.android.architecture.dialog

import android.view.View
import android.widget.TextView
import androidx.fragment.app.FragmentManager
import xyz.icxl.android.architecture.R
import xyz.icxl.android.architecture.ui.BaseDialogFragment

/**
 * 文件描述：XPower-Mall-Navigation
 *
 * 文件创建人：cxl
 *
 * 创建时间：2022 年 04月 11 日
 *
 * 文件版本：v1.0
 *
 * 版本描述：创建文件
 */
class AlertDialog : BaseDialogFragment() {
    companion object {
        fun show(
            manager: FragmentManager,
            message: CharSequence,
            buttonText:CharSequence? = null,
            onClickConfirmListener: View.OnClickListener? = null
        ) {
            AlertDialog().show(manager, message,buttonText, onClickConfirmListener)
        }
    }

    private var message: CharSequence = ""
    private var buttonText: CharSequence? = null
    private var onClickConfirmListener: View.OnClickListener? = null
    override fun layoutId(): Int = R.layout.dialog_alert

    override fun doSomething(rootView: View) {
        rootView.findViewById<TextView>(R.id.dialog_content_tv).text = message
        rootView.findViewById<TextView>(R.id.dialog_confirm_tv).apply {
            if(!buttonText.isNullOrEmpty()){
                text = buttonText
            }
            setOnClickListener {
                dismiss()
                onClickConfirmListener?.onClick(it)
            }
        }
    }

    fun show(
        manager: FragmentManager,
        message: CharSequence,
        buttonText:CharSequence? = null,
        onClickConfirmListener: View.OnClickListener? = null
    ) {
        super.show(manager, tag)
        this.message = message
        this.buttonText = buttonText
        this.onClickConfirmListener = onClickConfirmListener
    }
}